import { defHttp } from '/@/utils/http/axios';
import { useUserStore } from '/@/store/modules/user';
import { WorkParam} from './model/workModel';
import { computed } from 'vue';

import { BasicPageSearchParams } from "/@/api/model/baseModel";

const userStore = useUserStore();
const userId = computed(() => userStore.getUserInfo?.id);
//console.log('userId=', userId)



enum Api {
  getList = '/WorkTask/list',
  view = '/WorkTask/view/',
  approve = '/WorkTask/approve',
  
  GetCommentList = '/api/flow/getApps',
  Complete = '/api/flow/complete',
  StopProcess = '/api/flow/stopProcess',

  getBusinessData = '/work/getBusinessData', 
  getFlowData = '/work/getFlowData', 

  getSummary = '/index/getSummary', 
  transfer = '/WorkTask/transfer',

}




// 获取审批记录
export function getCommentInfosByProcessInstanceId(params: any) {
  return defHttp.post({ url: Api.GetCommentList + '/' + params.procInstId, params: {} });
}




// 1.待处理
// 2.已处理
// 3.抄送我

export function getWorkList(params: WorkParam) {
  const query = params && { pageNum: params.pageNum, pageSize: params.pageSize };
  let entity = params || {};
  entity.uid = userId.value

  let path = window.location.href
  if(path.indexOf('/work-todo') >0){
    entity.taskType = 1
  }else if(path.indexOf('/work-done') >0){
    entity.taskType = 2
  }else if(path.indexOf('/work-cc') >0){
    entity.taskType = 3
  }else{
    entity.taskType = 0
  }

  //console.log('path=', path, 'taskType=', entity.taskType)

  if (entity.dateRange) {
    entity['queryBegin'] = params.dateRange[0];
    entity['queryEnd'] = params.dateRange[1];
  }
  if (entity) {
    delete entity['pageNum'];
    delete entity['pageSize'];
    delete entity['dateRange'];
  }
  const queryParam = { query, entity } as BasicPageSearchParams<WorkParam>;
  return defHttp.post({ url: Api.getList, params: queryParam });
}

// 查看详情
export const view = (id?: number) => {
  return defHttp.get<any>({ url: Api.view + id });
}

// 审批
export const approve = (params) => {
  return defHttp.post({ url: Api.approve, params });
}

// 查看业务数据
export const businessdata = (params: any) => {
  return defHttp.get<any>({ url: Api.getBusinessData, params });
}

// 查看流程数据
export const workflowdata = (params: any) => {
  return defHttp.get<any>({ url: Api.getFlowData, params });
}

// 首页统计数据
export const getSummary = () => {
  return defHttp.get<any>({ url: Api.getSummary });
}

// 工作任务转交
export const transfer = (params) =>
  defHttp.post<any>({ url: Api.transfer, params });